﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using UnityEngine.SceneManagement;

// 登录界面控制类
public class Login : MonoBehaviour {

    InputField _inputAccount;
    InputField _inputPassword;
    Button _btnOK;

    private void Awake()
    {
        _inputAccount = transform.Find("InputFieldAccount").GetComponent<InputField>();
        _inputPassword = transform.Find("InputFieldPassword").GetComponent<InputField>();

        _btnOK = transform.Find("Button").GetComponent<Button>();
        _btnOK.onClick.AddListener(OnBtnOKClick);
    }

    private void OnBtnOKClick()
    {
        // 禁用整个界面

        // 连接并登录服务器
        Net.Instance.Connect(doLogin, null);
    }

    private void doLogin()
    {
        // 获取用户名和密码，传给服务器
        var account = _inputAccount.text;
        var password = _inputPassword.text;

        var cmd = new NCmd.Login();
        cmd.Account = account;
        cmd.Password = password;

        Net.Instance.SendCmd(cmd);
    }
}
